package com.lcl.jarvis.admin.modules.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.lcl.jarvis.admin.modules.business.dto.request.TbDoctorsPageReqDTO;
import com.lcl.jarvis.admin.modules.business.dto.request.TbDoctorsReqDTO;
import com.lcl.jarvis.admin.modules.business.dto.response.TbDoctorsRespDTO;
import com.lcl.jarvis.admin.modules.business.service.ITbDoctorsService;
import lombok.RequiredArgsConstructor;
import com.lcl.jarvis.common.model.R;
import com.lcl.jarvis.common.model.PageResult;

/**
 * 医生Controller
 *
 * @author licl
 * @date 2024-06-21 09:44:48
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/doctors")
public class TbDoctorsController {

    private final ITbDoctorsService tbDoctorsService;

    /**
     * 新增医生
     *
     * @param body
     * @return
     */
    @PreAuthorize("hasAuthority('business:doctors:add')")
    @PostMapping
    public R<Integer> add(@RequestBody TbDoctorsReqDTO body) {
        return R.succeed(tbDoctorsService.add(body));
    }

    /**
     * 删除医生
     *
     * @param ids
     * @return
     */
    @PreAuthorize("hasAuthority('business:doctors:remove')")
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@PathVariable List<Long> ids) {
        return R.succeed(tbDoctorsService.remove(ids));
    }

    /**
     * 修改医生
     *
     * @param body
     * @return
     */
    @PreAuthorize("hasAuthority('business:doctors:edit')")
    @PutMapping
    public R<Integer> update(@RequestBody TbDoctorsReqDTO body) {
        return R.succeed(tbDoctorsService.update(body));
    }

    /**
     * 获取医生详细信息
     *
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('business:doctors:query')")
    @GetMapping(value = "/{id}")
    public R<TbDoctorsRespDTO> detail(@PathVariable("id") Long id) {
        return R.succeed(tbDoctorsService.detail(id));
    }

    /**
     * 查询医生列表
     *
     * @param req
     * @return
     */
    @PreAuthorize("hasAuthority('business:doctors:list')")
    @GetMapping("/list")
    public R<PageResult<TbDoctorsRespDTO>> page(TbDoctorsPageReqDTO req) {
        return R.succeed(tbDoctorsService.page(req));
    }

}
